from db_connect.conn_mysql import ConnMysql
from db_connect.conn_redis import ConnRedis
from db_connect.conn_slave_mysql import ConnMysqlSlave
import aiomysql
import asyncio

class SpecificMethoD:

    # 具体的用法用法

    async def insert_info(self, sql=None, args=None):

        if args==None:
        
            async with ConnMysql().pool.acquire() as conn:

                await conn.ping()

                async with conn.cursor() as cur:
                    await cur.execute(sql)
                    await conn.commit()

                return "ok"

        else:

            async with ConnMysql().pool.acquire() as conn:
                
                await conn.ping()

                async with conn.cursor() as cur:
                    await cur.execute(sql,(args))
                    await conn.commit()
                    

                return 'ok'

    #具体的用法用法
    async def select_info(self, sql=None, args=None):

        if args==None:
        
            async with ConnMysqlSlave().pool.acquire() as conn:

                await conn.ping()

                async with conn.cursor(aiomysql.DictCursor) as cur:
                    await cur.execute(sql)
                    r = await cur.fetchall()

                return r

        else:

            async with ConnMysqlSlave().pool.acquire() as conn:
                
                await conn.ping()

                async with conn.cursor(aiomysql.DictCursor) as cur:
                    await cur.execute(sql,(args))
                    r = await cur.fetchall()

                return r

